package com.TestPage;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.zjg.db.utills.DBConnection;


@WebServlet("/testPage.servlet")
public class TestPageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=utf-8");
		Properties pre = new Properties();
		try {
			pre.load(TestPageServlet.class.getResourceAsStream("/test.page"));
		} catch (Exception e) {
			
		}
		
		String sql= pre.getProperty("pagefromtable");
		System.out.print(sql);
		String pagerows=request.getParameter("pagerows");
		String pagenumber=null==request.getParameter("nowpage")?"1":request.getParameter("nowpage");
		
		
		TestPageBean<List<Map<String,Object>>> page=new  TestPageBean<List<Map<String,Object>>>(Integer.parseInt(pagerows),sql);
			page.setNowPage(Integer.parseInt(pagenumber));
			new TestPageService().getDate(page);
			List<Map<String,Object>> list0=page.getPageDataMap();
			list0.stream().forEach((item)->{
				item.forEach((key,value)->{
					System.out.println(value);
				});
			});
			
			Map map=new HashMap();
			map.put("data", page);
			String json=JSON.toJSONString(map);
			PrintWriter out=response.getWriter();
			out.println(json);
			out.flush();
			out.close();
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		doGet(request, response);
	}

}
